﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace _MetalSlug.Form.SelectCharScreen
{
    public class MyCover : VisibleGameEntity
    {
        public const int MinPositionOfCover = -150;
        int MaxPositionOfCover;

        public enum STATE
        {
            OPEN,
            CLOSE
        }

        STATE currentState;
        public STATE CurrentState
        {
            get { return currentState; }
            set { currentState = value; }
        }

        int Time;

        Texture2D coverTexture;
        public Texture2D CoverTexture
        {
            get { return coverTexture; }
            set { coverTexture = value; }
        }

        Vector2 deltaCloseCover;
        public Vector2 DeltaCloseCover
        {
            get { return deltaCloseCover; }
            set { deltaCloseCover = value; }
        }

        public MyCover(String pathTexture)
        {
            CoverTexture = GameUtil.LoadTexture(pathTexture);
            CurrentState = STATE.OPEN;
        }

        public void SetTopLeft(Vector2 newPos, Vector2 newSize)
        {
            TopLeft = newPos;
            MaxPositionOfCover = (int)TopLeft.Y;
            Size = newSize;
        }

        public override void Update(GameTime gameTime)
        {
            Time++;
            if (Time > 50)
            {
                switch(CurrentState)
                {
                    case STATE.OPEN:
                        if (TopLeft.Y > MinPositionOfCover)
                        {
                            TopLeft -= DeltaCloseCover;
                        }
                        else
                        {
                            TopLeft = new Vector2(TopLeft.X, MinPositionOfCover);
                        }
                        break;

                    case STATE.CLOSE:
                        if (TopLeft.Y < MaxPositionOfCover)
                        {
                            TopLeft += DeltaCloseCover;
                        }
                        else
                        {
                            TopLeft = new Vector2(TopLeft.X, MaxPositionOfCover);
                        }
                        break;
                }
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(CoverTexture, new Rectangle((int)TopLeft.X, (int)TopLeft.Y, (int)Size.X, (int)Size.Y), Color.White);
        }

        public Boolean isOpenComplete()
        {
            if (CurrentState == STATE.OPEN && TopLeft.Y == MinPositionOfCover)
            {
                return true;
            }

            return false;
        }

        public Boolean isCloseComplete()
        {
            if (CurrentState == STATE.CLOSE && TopLeft.Y == MaxPositionOfCover)
            {
                return true;
            }

            return false;
        }
    }
}
